import pandas as pd
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error, r2_score
import joblib

df = pd.read_csv("hour.csv")

df = df.drop(columns = ["dteday"])
X = df.drop(columns = ["cnt"])
y = df["cnt"]

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.3, random_state = 100)

model = LinearRegression()
model.fit(X_train, y_train)
pred = model.predict(X_test)
print("R2 Score : ", r2_score(y_test, pred))
print("Mean Squared Error : ", mean_squared_error(y_test, pred))
joblib.dump(model, "linear_regression_model.pkl")
print("Model saves as Model1.pk1")